import React from 'react';
import { dictionaryList } from '@/services/dictionary';

// 获取职位列表的特殊字典
const useCityList = query => {
    const [data, setData] = React.useState([]);
    const [loading, setLoading] = React.useState(false);

    const fetchData = async () => {
        setLoading(true);

        const { data: datalist, code } = (await dictionaryList(query)) || {};

        if (code === 10000) {
            setData(datalist);
        }

        setLoading(false);
    };

    React.useEffect(() => {
        if (query.codes) {
            fetchData();
        }
    }, [query.code]);

    return [loading, data];
};

export default useCityList;
